package com.fitt.web.fotto.racetrack;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * <p> Description	: RaceIntegrationTest.groovy </p>
 * <p> Copyright	: Copyright (c) 2016 by PCI-SUNTEK</p>
 * <p> Author 		: ZCCHUN </p>
 * <p> Create		: 2016年1月25日 下午2:33:52 </p> 
 * <p> version 		: 1.0 </p>
 */
class RaceIntegrationTest extends GroovyTestCase {

	@Test
	public void testRaceDatasBeforeToday() {
		def lastWeek = new Date() - 7
		def race = new Race(startDate: lastWeek)
		
		assertFalse "Validation should be noe successed", race.validate()
		//验证失败后, 它应该有错误
		assertTrue "There should be errors", race.hasErrors()
		
		println "\nErros"
		println race.errors() ?: "no errors found"
		assertNotNull "Expecting to find an error on the startDate field", badField
		
		def code = badField?.codes.find {
			it == 'race.startDate.validator.invalid'
		}
		
		println "\nCode"
		println code ?: "the custom validator for startDate wasn't found"
		assertNotNull "startDate field shoule be the culprit", code
	}

}
